
const sizeType = {
    document: 1,
    element: 2,
    node: 3
}

function getSize() {

}
const size= new getSize()
getSize.prototype.getPreviousNode = function (node) {
    /*返回元素上一个兄弟元素*/
    return node.previousElementSibling
}

getSize.prototype.getDeviceType= function(){
    var documentSize= size.GET(sizeType.document)
    if (documentSize.width > 1024) {
        return "web";
      } else if (documentSize.width > 500 && documentSize.width <= 1024) {
        return "pad";
      } else {
        return "phone";
      }
}

getSize.prototype.GET = function (getType, args = null) {
    var m_size = {
        width: 0,
        height: 0,
        offsetWidth: 0,
        offsetHeight: 0,
        x: 0,
        y: 0,
    }
    switch (getType) {
        case sizeType.document: {
            m_size.width = document.documentElement.clientWidth || document.body.clientWidth;
            m_size.height = document.documentElement.clientHeight || document.body.clientHeight;
            break
        }
        case sizeType.element: {
            if (args != null) {
                var node = args
                if (node != null) {
                    m_size.offsetHeight = node.offsetHeight
                    m_size.offsetWidth = node.offsetWidth
                    m_size.width= node.clientWidth
                    m_size.height= node.clientHeight
                    m_size.x = node.offsetLeft
                    m_size.y = node.offsetTop
                }
            }
            break;
        }
        case sizeType.node: {
            if (args != null) {
                var node = args
                m_size.offsetHeight = node.offsetHeight
                m_size.offsetWidth = node.offsetWidth
                m_size.width= node.clientWidth
                m_size.height= node.clientHeight
                m_size.x = node.offsetLeft
                m_size.y = node.offsetTop
            }
            break;
        }
    }
    return m_size
};

export { size, sizeType }